# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator

# jdbcUrl = '{{ var.json.oracle_bi2.url }}'
# username = '{{ var.json.oracle_bi2.username }}'
# password = '{{ var.json.oracle_bi2.password }}'

# jdbcUrl = "jdbc:oracle:thin:@pro-bi02-readonly-ora.yl.com:1521/orcl"
jdbcUrl = "jdbc:oracle:thin:@xd2-rac-cluster-scan.yl.com:1521/orcllb"
username = "JMS_BI_BIGDATA"
password = "U88lCWTbVLoBr5bfW07s"


nowdt = '{{ execution_date | cst_ds }}'
nextdt = '{{ execution_date | date_add(1) | cst_ds }}'
table = "tab_day_intercept_turnback_d"
env = '{{ var.value.env_sync }}'

jsonpara = """{
"reader":{
"connect":{
"url":"jdbcUrlpara",
"username":"usernamepara",
"password":"passwordpara",
"driver":"oracle.jdbc.driver.OracleDriver"
},
"dbtype":"oracle",
"tableName":"tablepara",
"where":"1=1",
"query":"",
"splitColumn":"billcode",
"equalitySectioning":1,
"containsnull":0,
"fetchsize":"1024",
"threadNumber":6
},
"channel":{
"filterAbnormalCharacter":1
},
"writer":{
"dbtype":"hive",
"tableName":"tablepara",
"database":"jms_ods",
"writeMode": "overwrite",
"partitionColumn":"dt",
"partitionValue":"nowdt"},
"settting":{
"env":"envpara"}
}""".replace("jdbcUrlpara", jdbcUrl).replace("usernamepara", username).replace("passwordpara", password). \
    replace("nowdt", nowdt).replace("nextdt", nextdt). \
    replace("tablepara", table). \
    replace("envpara", env)

jms_ods__tab_day_intercept_turnback_d = SparkSubmitOperator(
    task_id='jms_ods__tab_day_intercept_turnback_d',
    email=['chenhongping@yl-scm.com','yl_bigdata@yl-scm.com'],
    name='jms_ods__tab_day_intercept_turnback_d_{{ execution_date | date_add(1) | cst_ds }}',
    pool='oracle_tms',
    pool_slots=2,
    execution_timeout=timedelta(hours=2),
    driver_memory='2G',
    executor_memory='3G',
    executor_cores=2,
    num_executors=3,
    java_class='com.yunlu.bigdata.jobs.synchrotool.DataSynchDriver',  # spark 主类
    application='hdfs:///scheduler/jms/spark/sync/spark_sync.jar',  # spark jar 包
    application_args=[jsonpara, ],
    sla=timedelta(hours=3),
)
